<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>导出中心</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
    <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
    <style>
        .edit{background-color: #ed9c3a;}
        .shenhe{background-color: #429488;}
        .see{background-color: #7cb717;}
        .tongbu{background-color: #4c9ef8;color:#fff;border-radius:3.5px}
        .cur{color:#21c4f5;}
        .userbox,.storebox{height:190px;margin-right:0; overflow-y: auto; z-index: 999; position: absolute; left: 0px; top: 63px; width:298px; background-color:#ffffff; border: 1px solid #ddd;}
        .userbox .list,.storebox .list{height:38px;line-height: 38px;cursor:pointer; padding-left:10px;}
        .userbox .list:hover,.storebox .list:hover{background-color:#eeeeee;}
        .yname{font-size: 13px; color: #444; margin-bottom:8px;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="margin-top:0px">
            <div class="layui-fluid">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header">导出中心</div>
                            <div class="layui-card-body">
                                <div class="layui-btn-container" style="font-size:14px;">
                                    <div style="font-size:14px">
                                        <div class="layui-form" lay-filter="component-form-group" style="width: 100%;margin-right:0;display: inline-block;">
                                            <div class="layui-form-item">
                                                <!-- <div class="layui-input-block" style="margin-left:5px;border-radius:5px">

                                                    <div class="layui-inline">
                                                        <div class="layui-input-inline">
                                                            <text class="yname">交易开始时间</text>
                                                            <input type="text" class="layui-input start-item test-item" placeholder="交易开始时间" lay-key="23">
                                                        </div>
                                                    </div>
                                                    <div class="layui-inline">
                                                        <div class="layui-input-inline">
                                                            <text class="yname">交易结束时间</text>
                                                            <input type="text" class="layui-input end-item test-item" placeholder="交易结束时间" lay-key="24">
                                                        </div>
                                                    </div>
                                                    <div class="layui-inline">
                                                        <div class="layui-input-inline" style="margin-left:5px;border-radius:5px;width: 300px;">
                                                            <text class="yname">门店名称</text>
                                                            <input type="text" style="border-radius:5px; width: 300px; display: inline-block;" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="请输入门店名称" class="layui-input inputstore">
                                                            <div class="storebox" style='display: none'></div>
                                                        </div>
                                                    </div>

                                                    <div class="layui-inline">
                                                        <button class="layui-btn layui-btn-normal" style="border-radius:5px;margin-top:31px;" id="search">搜索</button>

                                                        <button class="layui-btn export" style="border-radius:5px;margin-top:31px;">导出</button>
                                                    </div>

                                                </div> -->



                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <table class="layui-hide" id="test-table-page" lay-filter="test-table-page"></table>

                                <!-- 判断状态 -->
                                <!-- <script type="text/html" id="statusTap">
                                    @{{#  if(d.status == 1){ }}
                                    <span class="cur">成功</span>
                                    @{{#  } else if(d.status == 0){ }}
                                        等待
                                    @{{#  } else if(d.status == 2){ }}
                                        失败
                                    @{{#  } else {  }}
                                        @{{ d.status }}
                                    @{{#  } }}
                                </script> -->
                                <!-- 判断状态end -->

                                <!-- 通道类型 -->


                                <script type="text/html" id="table-content-list" class="layui-btn-small">
                                    @{{#  if(d.status == 1){ }}
                                    <a class="layui-btn layui-btn-normal layui-btn-xs exports" lay-event="exports">下载</a>
                                    @{{#  } else if(d.status == 0){ }}
                                    <a lay-event="" style="color:red">生成中...</a>
                                    @{{#  } else { }}
                                    <a lay-event="" style="color:red">生成失败</a>
                                    @{{#  } }}
                                    
                                </script>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="store_id">
<input type="hidden" class="sort">
<input type="hidden" class="stu_class_no">

<input type="hidden" class="stu_order_batch_no">
<input type="hidden" class="user_id">

<input type="hidden" class="pay_status">
<input type="hidden" class="pay_type">

<input type="hidden" class="paycode">
<input type="hidden" class="company_id">

<input type="hidden" class="sbid">
<input type="hidden" class="danhao">
<input type="hidden" class="tiaoma">

<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script>
<script>
    var token = localStorage.getItem("Usertoken");
    var str=location.search;
    var store_id=str.split('?')[1];

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;

        $('.store_id').val(store_id);

        // 未登录,跳转登录页面
        $(document).ready(function(){
            if(token==null){
                window.location.href="{{url('/user/login')}}";
            }
        });

        // $(".transfer").bind("input propertychange",function(event){
        //     //         console.log($(this).val());
        //     user_name = $(this).val();
        //     if (user_name.length == 0) {
        //         $('.userbox').html('');
        //         $('.userbox').hide();
        //     } else {
        //         $.post("{{url('/api/user/get_sub_users')}}",
        //             {
        //                 token:token
        //                 ,user_name:$(this).val()
        //                 ,self:'1'
        //             },function(res){
        //                 var html="";

        //                 if(res.t==0){
        //                     $('.userbox').html('');
        //                 }else{
        //                     for(var i=0;i<res.data.length;i++){
        //                         html+='<div class="list" data='+res.data[i].id+'>'+res.data[i].name+'-'+res.data[i].level_name+'</div>'
        //                     }
        //                     $(".userbox").show();
        //                     $('.userbox').html('');
        //                     $('.userbox').append(html);
        //                 }
        //             },"json");
        //     }
        // });

        // $(".userbox").on("click",".list",function(){
        //     $('.transfer').val($(this).html());
        //     $('.user_id').val($(this).attr('data'));
        //     $('.userbox').hide();

        //     table.reload('test-table-page', {
        //         where: {
        //             user_id:$(this).attr('data'),
        //             store_id:$('store_id').val()
        //         }
        //         ,page: {
        //             curr: 1
        //         }
        //     });
        // });

        // $(".inputstore").bind("input propertychange",function(event){
        //     var store_name = $(this).val();
        //     if (store_name.length == 0) {
        //         $('.storebox').html('');
        //         $('.storebox').hide();
        //         $('.store_id').val('')
        //     } else {
        //         $.post("{{url('/api/user/store_lists')}}",
        //         {
        //             token:token
        //             ,store_name:$(this).val()
        //             ,l:100
        //         },function(res){
        //             var html="";
        //             if(res.t==0){
        //                 $('.storebox').html('');
        //             }else{
        //                 for(var i=0;i<res.data.length;i++){
        //                     html+='<div class="list" data='+res.data[i].store_id+'>'+res.data[i].store_name+'</div>'
        //                 }
        //                 $(".storebox").show();
        //                 $('.storebox').html('');
        //                 $('.storebox').append(html);
        //             }
        //         },"json");
        //     }
        // });

        // $(".storebox").on("click",".list",function(){
        //     $('.inputstore').val($(this).html());
        //     $('.store_id').val($(this).attr('data'));
        //     $('.storebox').hide();

        //     // table.reload('test-table-page', {
        //     //     where: {
        //     //         user_id:$('user_id').val(),
        //     //         store_id:$(this).attr('data')
        //     //     }
        //     //     ,page: {
        //     //         curr: 1
        //     //     }
        //     // });

        //     // $("#passway").html('');

        // });

        table.render({
            elem: '#test-table-page',
            url: "{{url('/api/v2/Order/User/OrderQuery/getOrderExportList')}}",
            // url: ""
            method: 'get',
            where:{
                token: token,
            },
            request: {
                pageName: 'page',
                limitName: 'pageSize'
            },
            page: true,
            cellMinWidth: 100,
            cols: [[
                {field: 'id', align: 'left', title: 'id'},
                {field: 'export_query', align: 'left', title: '订单范围',templet:function(info){
                    let value = ''
                    if(info.export_query){
                        let query = JSON.parse(info.export_query);
                        value = `${query.start_date || ''}-${query.end_date || ''}`
                    }
                    return value
                }},
                // {field: 'status', align: 'center', title: '文件状态',templet:'#statusTap'},
                {field: 'export_status', align: 'center', title: '导出状态',templet:function(info){
                    let title = ''
                    if(info.export_status == 0){
                        title = '未下载'
                    }else if(info.export_status == 1){
                        title = '已下载'
                    }else{
                        title = info.export_status
                    }
                    return title
                }},
                {field: 'created_at', align: 'center', title: '创建时间'},
                {width:150,align:'center', fixed: 'right', toolbar: '#table-content-list',title: '操作'}
            ]],
            response: {
                statusName: 'status', //数据状态的字段名称，默认：code
                statusCode: 1, //成功的状态码，默认：0
                msgName: 'message', //状态信息的字段名称，默认：msg
                countName: 'total', //数据总数的字段名称，默认：count
                dataName: 'list', //数据列表的字段名称，默认：data
            },
            done: function(res, curr, count){
                $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
                // if(pageLoading){
                //     layer.close(pageLoading);
                // }
            }
        });

        table.on('tool(test-table-page)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var e = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //          console.log(e);
            // localStorage.setItem('s_store_id', e.store_id);

            if(layEvent === 'exports'){ //同步
                let exporturl = e.link;
                if(exporturl){
                    let urls = exporturl.replace(/http:\/\//i, 'https://');
                    window.location.href=urls;
                    $.ajax({
                        url : "{{url('/api/v2/Order/User/OrderQuery/OrderExportSaveExportStatus')}}",
                        data : {
                            token:token,
                            id:e.id
                        },
                        dataType:'json',
                        type : 'post',
                        success : function(data) {
                            table.reload('test-table-page', {});
                        },
                        error : function(data) {
                            alert('请求失败');
                        }
                    });
                }
            }else if(layEvent === 'exportDisabled'){
                layer.msg('当前导出文件未生成成功，请稍后刷新重试！', {icon: 2, time: 2000});
            }
        });

        // 选择门店
        form.on('select(schooltype)', function(data){
            var store_id = data.value;
            $('.store_id').val(store_id);

            //执行重载
            table.reload('test-table-page', {
                where: {
                    store_id: store_id
                    ,user_id:$('.user_id').val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        laydate.render({
            elem: '.start-item'
            ,type: 'date'
            ,done: function(value){
                //执行重载
                // table.reload('test-table-page', {
                //     where: {
                //         time_start:value
                //         ,time_end:$('.end-item').val()
                //     }
                //     ,page: {
                //         curr: 1 //重新从第 1 页开始
                //     }
                // });
            }
        });

        laydate.render({
            elem: '.end-item'
            ,type: 'date'
            ,done: function(value){
                //执行重载
                // table.reload('test-table-page', {
                //     where: {
                //         time_start:$('.start-item').val()
                //         ,time_end:value
                //     }
                //     ,page: {
                //         curr: 1 //重新从第 1 页开始
                //     }
                // });
            }
        });

        form.on('submit(LAY-app-contlist-search)', function(data){

            // var paytradeno = data.field.paytradeno;  //条码单号
            // var out_trade_no = data.field.tradeno; //订单号
            // var device_id = data.field.deviceid;
            //
            // $('.danhao').val(out_trade_no);
            // $('.tiaoma').val(paytradeno);
            // $('.sbid').val(device_id);

            var store_name = $('.inputstore').val();

            //执行重载
            table.reload('test-table-page', {
                where: {
                    store_name: store_name
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        $('.export').click(function(){
            var exportLoading = layer.msg('数据导出中..', {
                icon: 16
                ,shade: 0.3
                ,time: false
            });
            let params = {
                token: token,
                store_created_start_date: $('.start-item').val(),
                store_created_end_date: $('.end-item').val(),
                store_id: $('.store_id').val(),
            }
            $.ajax({
                url : "{{url('/api/v2/Bill/User/Count/storeCompanyGroupCountListExport')}}",
                data : {
                    token:token,
                    ...params
                },
                dataType:'json',
                type : 'post',
                success : function(data) {
                    layer.close(exportLoading);
                    if (data.status == 1) {
                        layer.close(exportLoading);
                        let urls = data.url.replace(/http:\/\//i, 'https://');
                        window.location.href=urls;
                    } else {
                        layer.msg(data.message);
                    }
                },
                error : function(data) {
                    layer.close(exportLoading);
                    alert('查找板块报错');
                }
            });
        })

        // 搜索
        $('#search').click(function(){

            // var type = $('#agent').val();

            // console.log( $('.start-item').val() )

            // $('.start-item').val($('.starttimeY').val());
            // $('.end-item').val($('.endtimeY').val());
            // var pageLoading = layer.msg('数据请求中..', {
            //     icon: 16
            //     ,shade: 0.3
            //     ,time: false
            // });
        });

    });
</script>

</body>
</html>